/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Category;
import entity.Product;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author osman
 */
@ManagedBean(name = "categoryFacade")
@SessionScoped
@Stateless
public class CategoryFacade extends AbstractFacade<Category> {

	@PersistenceContext(unitName = "jsf_crudPU")
	private EntityManager em;

	@Override
	protected EntityManager getEntityManager() {
		return em;
	}

	public CategoryFacade() {
		super(Category.class);
	}

	public Category find(String id) {
		return (Category) em.find(Category.class, Short.valueOf(id));
	}

	public Collection<Product> getProductCollection(String id) {
		Category c = (Category) em.find(Category.class, Short.valueOf(id));
		return c.getProductCollection();
	}
}
